package com.example.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.studyapplication.R;

/**
 * @Description:
 * @Author: 葛浩杰
 * @Version: 1.0 2021/4/21
 */
public class PkMakeUpView extends FrameLayout {

    private PkView mPv;
    private TextView mTvLefeCount;
    private TextView mTvRightCount;
    private TextView mTvLeft;
    private TextView mTvRight;
    private TextView mTvLeftBtn;
    private TextView mTvRightBtn;
    private View mViewImg;

    private View view;

    public PkMakeUpView(@NonNull Context context) {
        super(context);
    }

    public PkMakeUpView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        view = View.inflate(context, R.layout.custom_pk_view, this);
        mPv = view.findViewById(R.id.pv);
        mTvLefeCount = view.findViewById(R.id.tv_left_count);
        mTvRightCount = view.findViewById(R.id.tv_right_count);
        mTvLeft = view.findViewById(R.id.tv_left);
        mTvRight = view.findViewById(R.id.tv_right);
        mTvLeftBtn = view.findViewById(R.id.tv_left_btn);
        mTvRightBtn = view.findViewById(R.id.tv_right_btn);
        mViewImg = view.findViewById(R.id.view_img);
    }

    /**
     * 设置选票类型 1左侧 2右侧 3未选
     * @param voteType
     */
    public void setVoteType(int voteType){
        if(voteType != 3){
            mTvLeftBtn.setVisibility(View.GONE);
            mTvRightBtn.setVisibility(View.GONE);
            mTvLefeCount.setVisibility(View.VISIBLE);
            mTvRightCount.setVisibility(View.VISIBLE);
        } else {
            mTvLeftBtn.setVisibility(View.VISIBLE);
            mTvRightBtn.setVisibility(View.VISIBLE);
            mTvLefeCount.setVisibility(View.GONE);
            mTvRightCount.setVisibility(View.GONE);
        }
        mPv.setVoteType(voteType);
    }

    /**
     * 设置左侧支持文字
     * @param text
     */
    public void setLeftText(String text){
        mTvLeft.setText(text);
    }

    /**
     * 设置右侧支持文字
     * @param text
     */
    public void setRightText(String text){
        mTvRight.setText(text);
    }

    /**
     * 设置左侧票数
     * @param text
     */
    public void setLeftCount(int text){
        mTvLefeCount.setText(text + "票");
    }

    /**
     * 设置右侧票数
     * @param text
     */
    public void setRightCount(int text){
        mTvRightCount.setText(text + "票");
    }
}
